package com.hhh.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhh.Mapper.UserMapper;
import com.hhh.Pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserSerivce implements com.hhh.Service.UserSerivce {
    @Autowired
    UserMapper userMapper;

    //    添加用户信息
    @Override
    @Transactional
    public Integer Insert(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone", user.getPhone());
        long num = userMapper.selectCount(wrapper);
        if (num == 0)
            return userMapper.insert(user);

        return 1;
    }

    //    查询用户信息
    @Override
    public User Select(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone", user.getPhone());
        return userMapper.selectOne(wrapper);
    }

    //    根据id查询用户信息
    @Override
    public User SelectById(User user) {
        return userMapper.selectById(user.getId());
    }
}
